package com.lamatek.tags.google;

import java.io.Serializable;

import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.Tag;

import com.lamatek.tags.google.beans.EscapeChars;

/**
 * GoogleMapBodyTag
 * 
 * This tag corresponds to the body contents of the GoogleMapTag. This is
 * for advanced javascript programmers who can use it to add custom map controls.
 * This class should not be overriden by developers.
 * 
 * @author Tom Cole
 * @version 0.40
 */
public class GoogleMapBodyTag extends BodyTagSupport implements Serializable {

    String content = "";
    boolean html = false;
    /**
     * Overrides doStartTag() in BodyTagSupport.
     */
    public int doStartTag() {
        return EVAL_BODY_BUFFERED;
    }
    /**
     * Overrides doEndTag() in BodyTagSupport. Developers should not
     * override this method.
     */
    public int doEndTag() {
        content = getBodyContent().getString().trim();
        if (html)
            content = EscapeChars.escape(content);
        Tag tag = this;
        while (tag.getParent() != null) {
            if (tag.getParent() instanceof GoogleMapTag) {
                ((GoogleMapTag) tag.getParent()).setBody(content);
                return EVAL_PAGE;
            }
            tag = tag.getParent();
        }
        return EVAL_PAGE;
    }
    /**
     * Denotes whether or not the body contains html. If true, then the content
     * will be escaped, otherwise it is left as is.
     * 
     * @return True if content contains html, false otherwise.
     */
    public boolean isHtml() {
        return html;
    }
    /**
     * Sets whether or not the body contains html. If true, then the content
     * will be escaped, otherwise it is left as is.
     * 
     * @param html True or false.
     */
    public void setHtml(boolean html) {
        this.html = html;
    }
}
